<?php
namespace Admin\Controller;

class PointController extends AdminController{
	//加载积分规则页面
	public function index(){
		$data = new \Think\Model();
		$result = $data ->query('select id,uid,name,integral from love_userinfo');
		var_dump($result);
		$this->assign('list',$result);
		$this->display();
	}


	public function details(){
		$uid = I('get.uid/d');
		$data = new \Think\Model();
		$result = $data->query("select i.name,i.uid iuid,g.uid guid,g.utime,g.type,g.value,g.reason from love_userinfo i,love_integral g where i.uid=$uid and g.uid = $uid");
		/*$data = M('integral')->where("uid=$uid")->select();*/
		/*var_dump($result);*/
		$this->assign('list',$result);

		$this->display();
	}


	public function yingyong(){
		session('rule',$_POST['rule']);
		session('dict',$_POST['dict']);
		/*var_dump($_SESSION);*/

		$this->redirect('Point/index');
	}

	public function update(){
		/*var_dump($_POST);*/
		$_POST['utime'] = time();
		$uid=$_POST['uid'];
		$data= new \Think\Model();
		$result=$data->query("select integral from love_userinfo where uid = $uid");
		/*var_dump($result);*/
		$integral = $result[0]['integral'];
		if($_POST['deal'] == '增加'){
			$_POST['type']=1;
			$ral = $integral + $_POST['value'];
		}else{
			$_POST['type']=0;
			$ral = $integral - $_POST['value'];
		}
		M('userinfo')->integral =$ral;
		
		M('integral')->create();

		$a = M('integral')->add();
		if($a>0){
			if(M('userinfo')->where("uid=$uid")->save()>0){
				$this->success('积分修改成功！',U('index'));
			}else{
				$this->error('积分修改失败');
			}
		}

	}

}